<template>
<div class="page">
    <div class="weui-msg">
        <div class="weui-msg__icon-area"><i v-bind:class="[SUCCESS==true ? 'weui-icon-success' : 'weui-icon-warn', 'weui-icon_msg']"></i></div>
        <div class="weui-msg__text-area">
            <h2 class="weui-msg__title">{{TITLE}}</h2>
            <p class="weui-msg__desc">{{INFO}}</p>
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:void(0);" class="weui-btn weui-btn_primary" v-on:click="onGoBack" v-if="SUCCESS==true">继续操作</a>
                <a href="javascript:void(0);" class="weui-btn weui-btn_default" v-on:click="onCloseWindow">关闭页面</a>
            </p>
        </div>
        <div class="weui-msg__extra-area">
            <div class="weui-footer">
                <p class="weui-footer__text">Copyright &copy; 2018 910医院信息科</p>
            </div>
        </div>
    </div>
</div>
</template>

<script>
var wx = require('weixin-js-sdk');

export default {
    data: function () {
        return {
            TITLE: "操作成功",
            INFO: "",
            SUCCESS: true,
            GOTO:''
        }
    },
    methods: {
        onGoBack: function () {
            if(this.GOTO && this.GOTO!=""){
                this.$router.replace({ name: this.GOTO });
            }
            else{
                this.$router.go(-1);
            }
            
        },
        onCloseWindow: function () {
            try{
                wx.closeWindow();
            }
            catch(ex){
                window.close();
            }
        }
    },
    created: function () {
        if(this.$route.query.SUCCESS===true || this.$route.query.SUCCESS==="true")
            this.SUCCESS = true;
        else
            this.SUCCESS = false;
        this.TITLE = this.SUCCESS==true ? "操作成功" : "操作失败";
        document.title=this.TITLE;
        this.INFO = this.$route.query.INFO;
        this.GOTO = this.$route.query.GOTO;
        //获取微信关闭权限
        this.$api.Common.JSSDK({url: window.location.href}).then((msg) => {
            if (msg.data.R) {
                //初始化微信sdk
                wx.config({
                    beta: true, // 必须这么写，否则wx.invoke调用形式的jsapi会有问题
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: msg.data.D.AppId, // 必填，企业微信的corpID
                    timestamp: msg.data.D.Timestamp, // 必填，生成签名的时间戳
                    nonceStr: msg.data.D.NonceStr, // 必填，生成签名的随机串
                    signature: msg.data.D.Signature, // 必填，签名，见附录1
                    jsApiList: ['closeWindow'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
                });
            }
            else {
                //weui.alert("初始化微信sdk错误，原因:" + msg.data.I);
            }
        }).catch(() => {
            // 响应错误回调
            //weui.alert("调用http错误，代码:" + response.message);
        });
    }
}
</script>

<style></style>